Skip to content

merge: keep conflict markers on their own lines when hunks lack a trailing newline#85

Merged
bmwill merged 1 commit into
bmwill:masterfrom
jochenhz:fix/merge-conflict-marker-newlines
Jul 19, 2026
Merged

merge: keep conflict markers on their own lines when hunks lack a trailing newline#85
bmwill merged 1 commit into
bmwill:masterfrom
jochenhz:fix/merge-conflict-marker-newlines

Conversation

@jochenhz

Copy link
Copy Markdown
Contributor

When a conflicting hunk sits at end-of-file without a trailing newline, merge/merge_bytes
glue the next conflict marker onto the content line, producing unparseable output:

    base:   "This is line 1.\nThis is line 2."
    ours:   "This is line 1.\nThis is line 2 changed."
    theirs: "This is line 1.\nThis is line 2 also changed."

Actual:

    This is line 1.
    <<<<<<< ours
    This is line 2 changed.||||||| original
    This is line 2.=======
    This is line 2 also changed.>>>>>>> theirs

Expected (matches git merge-file --diff3 on identical inputs):

    This is line 1.
    <<<<<<< ours
    This is line 2 changed.
    ||||||| original
    This is line 2.
    =======
    This is line 2 also changed.
    >>>>>>> theirs

add_conflict_marker/add_conflict_marker_bytes now prefix a newline when the output
doesn't already end with one. Only reachable for file-final hunks, so all existing merge
output is unchanged — the full suite passes untouched. One new test covers both the str
and bytes paths via assert_merge!.

A conflicting hunk at end-of-file without a trailing newline glued the
next marker onto its last content line, producing unparseable output.
Matches git merge-file --diff3 behavior.

Signed-off-by: Jochen Hunz <j.hunz@anchorpoint.app>
jochenhz added a commit to Anchorpoint-Software/lore that referenced this pull request Jul 18, 2026
Vendor diffy 0.4.2 with a newline guard in both conflict-marker
builders until a release contains the upstream fix
(bmwill/diffy#85).

Signed-off-by: Jochen Hunz <j.hunz@anchorpoint.app>
@bmwill

bmwill commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Thanks for the fix! Looks like there are some issues with CI unrelated to your PR (newer git on the CI machines changing an expected output string and some new clippy lint). I'll fix those and get this merged in.

@bmwill
bmwill merged commit 31de940 into bmwill:master Jul 19, 2026
21 of 26 checks passed
@bmwill

bmwill commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Alright merged and just published version 0.5.1 with your fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants